package cn.jx.asc.lhg.bzxq.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import cn.jx.asc.lhg.bzxq.*;
import cn.jx.asc.lhg.bzxq.utils.SoundUtils;

public class MainActivity extends Activity {

    EditText edit;
    Button btn_1,btn_2,btn_3,btn_4,btn_5;
    String name; //玩家游戏名
    SoundUtils soundUtils;
    App app;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        app = (App) getApplication();
        //初始化控件
        initview();
        //初始化事件
        initevent();
    }

    public void initview(){
        edit = (EditText) findViewById(R.id.main_edit);
        btn_1 = (Button) findViewById(R.id.main_btn);
        btn_2 = (Button) findViewById(R.id.main_btn_2);
        btn_3 = (Button) findViewById(R.id.main_btn_3);
        btn_4 = (Button) findViewById(R.id.main_btn_4);
        btn_5 = (Button) findViewById(R.id.main_btn_5);
    }
    public void initevent(){
        btn_1.setOnClickListener(click);
        btn_2.setOnClickListener(click);
        btn_3.setOnClickListener(click);
        btn_4.setOnClickListener(click);
        btn_5.setOnClickListener(click);
    }

    View.OnClickListener click = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            soundUtils = new SoundUtils(MainActivity.this, SoundUtils.RING_SOUND);
            switch (v.getId()){
                case R.id.main_btn:
                    //开始播放音效
                    soundUtils.putSound(0, R.raw.btn_yin);
                    soundUtils.playSound(0, SoundUtils.SINGLE_PLAY);
                    name = edit.getText().toString();
                    if(name!=null&&!name.equals("")){
                        app.setName(name);
                        Intent it = new Intent(MainActivity.this, BaoZaoDeXiaoQiu.class);
                        startActivity(it);
                    }else{
                        Toast.makeText(MainActivity.this, "游戏名不能为空！", Toast.LENGTH_SHORT).show();
                    }
                    break;
                case R.id.main_btn_2:

                    //开始播放音效
                    soundUtils.putSound(0, R.raw.btn_yin);
                    soundUtils.playSound(0, SoundUtils.SINGLE_PLAY);
                    Intent it = new Intent(MainActivity.this, BangDan.class);
                    startActivity(it);
                    break;
                case R.id.main_btn_3:
                    Intent intent=new Intent(MainActivity.this,GameInstructions.class);
                    startActivity(intent);
                    break;
                case R.id.main_btn_4:
                    Intent intent1=new Intent(MainActivity.this,AboutTheGame.class);
                    startActivity(intent1);
                    break;
                case R.id.main_btn_5:
                    Intent intent2=new Intent(MainActivity.this,PersonalRecord.class);
                    startActivity(intent2);
                    break;
                default:{

                }
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        soundUtils.stop();
    }
}
